package com.blog.service.impl;

import com.blog.mapper.LogMapper;
import com.blog.pojo.Log;
import com.blog.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Slf4j //Lombok
@Service
public class LogServiceImpl implements LogService {
    //private static final Logger log=
            //LoggerFactory.getLogger(LogServiceImpl.class);
    @Autowired
    private LogMapper logMapper;

    /**
     *  @Async注解描述的方法会运行在spring提供的线程中
     *  @param userLog
     *  注意:@Async描述的方法会在新的线程中执行，是底层AOP对这个业务进行了封装，
     *  这个注解描述的方法可以理解为切入点方法。
     */
    @Async
    @Override
    public void insert(Log userLog) {
        log.info("before");
        System.out.println("LogService.insert.thread.name->"+Thread.currentThread().getName());
        logMapper.insert(userLog);
        //模拟耗时操作
        try{Thread.sleep(5000);}catch (Exception e){}
    }
}
